<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			// 定义一个对象
			var $ = function(key){
				var id;
				var value = ''; 
				if(key.startsWith('#')){
					id = key.substring(1);
					value = document.getElementById(id).value;
				}
				this.val = function(v){
					if(v){
						document.getElementById(id).value = v;
					}else{
						return value;
					}
				}
				return this;
			}
			
			function showValue(){
				alert('value is [' + $('#test').val() + ']');
			}
			
			function setValue(){
				var value = prompt('请输入');
				$('#test').val(value);
			}
		</script>
	</head>
	<body>
		<h1>仿JQuery</h1>
		<input type="button" value="查看" onclick="showValue()"/>
		<input type="button" value="设置" onclick="setValue()"/><br />
		<input id="test" type="text" value=""/>
	</body>
</html>
